<template>

  <div class="showuser">
      <h1>用户信息</h1>
    <table border="1" cellspacing="0" class="show_table">
        <tr>
            <td>姓名</td>
            <td>邮箱</td>
            <td>手机号</td>
            <td>权限</td>
            <td>状态</td>
            <td>操作</td>
        </tr>
        <tr v-if="type!=5" >
            <td>{{ userlist.username }}</td>
            <td>{{userlist.email}}</td>
            <td>{{userlist.phone}}</td>
            <td v-if="userlist.type==1">收货</td>
            <td v-if="userlist.type==2">发货</td>
            <td v-if="userlist.type==3">收货+发货</td>
            <td v-if="userlist.type==4">客服</td>
            <td v-if="userlist.type==5">管理员</td>
            <td v-if="userlist.auditing==0">待审核</td>
            <td v-if="userlist.auditing==1">审核通过</td>
            <td v-if="userlist.auditing==2">审核失败</td>
        </tr>

        <tr v-else v-for="item in userlist">
            <td>{{ item.username }}</td>
            <td>{{item.email}}</td>
            <td>{{item.phone}}</td>
            <td v-if="item.type==1">收货</td>
            <td v-if="item.type==2">发货</td>
            <td v-if="item.type==3">收货+发货</td>
            <td v-if="item.type==4">客服</td>
            <td v-if="item.type==5">管理员</td>
            <td v-if="item.auditing==0">待审核</td>
            <td v-if="item.auditing==1">审核通过</td>
            <td v-if="item.auditing==2">审核失败</td>
            <td v-if="item.auditing==1"><Button color="red" @click="del(item.id)">存档</Button></td>
            <td v-if="item.auditing==0"><Button color="green" @click="via(item.id)">审核通过</Button><Button color="red">存档</Button></td>
        </tr>
    </table>
  </div>
</template>
<style>
  .show_table{
    box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
    border-radius: 4px
  }
  .showuser {
    background-color: rgb(219, 221, 224);
    line-height: 60px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, .12), 0 0 6px rgba(0, 0, 0, .04)
  }
</style>
<script>

import { show_post,audit_post,del_post } from './axios_api/api';
export default {
  data() {
    return {
            userlist:[],
            type:""
    };
  },

  mounted(){
      this.getuser();
      this.type = localStorage.getItem('type')
  },
  methods: {
    del(id){
      var data = {id:id}
      del_post(data).then(resp=>{
          this.$Message(resp.message)
      })
    },
    via(id){
      var data = {id:id}
      audit_post(data).then(resp=>{
          this.$Message(resp.message)
      })
    },
      getuser(){
          var uid = localStorage.getItem('uid')
          var data = {uid:uid}
          show_post(data).then(resp=>{
              this.userlist = resp.userlist;
              console.log(this.userlist)
          })
      },
  }
};
</script>